<?php


namespace app\admin\controller;


use app\admin\model\Banner as BannerModel;
use app\admin\model\Notice as NoticeModel;
use app\common\controller\AdminController;
use think\Exception;
use think\facade\Request;

class Banner extends AdminController {

    protected $levelConfig = [
        1 => ['getlist', 'wherelist'],
        2 => ['editsort', 'addpost', 'editget','editpost', 'del'],
        4 => [],
        8 => []
    ];

    public $resubmitLock = ['addpost','editpost'];

    /**
     * 条件
     * @return false|string
     */
    public function whereList() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = BannerModel::$where;
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 列表
     * @return false|string
     */
    public function getList() {
        try {
            $params = $this->checkParams('');
            if ($params === false) return $this->resErr();
            $list = BannerModel::getList($params);
            return $this->resData('success', $list);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 修改排序
     * @return false|string
     * @throws \Exception
     */
    public function editSort() {
        try {
            $params = $this->checkParams('ids');
            if ($params === false) return $this->resErr();
            BannerModel::editSort($params);
            return $this->resData('success', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 新增提交
     * @return false|string
     */
    public function addPost() {
        try {
            $params = $this->checkParams('seat,url');
            if ($params === false) return $this->resErr();
            $res = BannerModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('添加成功😃', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑获取
     * @return false|string
     */
    public function editGet() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = BannerModel::info($params['id'], $info);
            if (!$res) return $this->resErr();
            else return $this->resData('success', $info);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 编辑提交
     * @return false|string
     */
    public function editPost() {
        try {
            $params = $this->checkParams('seat,url,id');
            if ($params === false) return $this->resErr();
            $res = BannerModel::post($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 删除
     * @return false|string
     */
    public function del() {
        try {
            $params = $this->checkParams('id');
            if ($params === false) return $this->resErr();
            $res = BannerModel::del($params);
            if (!$res) return $this->resErr();
            else return $this->resData('操作成功', []);
        } catch (Exception $e) {
            return $this->resErr($e->getMessage(), $e->getCode());
        }
    }

}
